<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    // 创建构造函数
    function Person(name, sex, age) {
      this.name = name;
      this.sex = sex;
      this.age = age;
      this.show = function () {
        console.log("您的信息为：" + this.name + this.sex + this.age);
      };
    }
    Person.prototype.classic = "学生"; //为Person构造函数添加了一个共享属性classic
    Person.prototype.play = function () {
      //为Person构造函数添加了一个共享方法
      console.log("喜欢打篮球！");
    };
    console.dir(Person);

    // 通过构造函数实例化对象
    var zs = new Person("张三", "男", "18");
    console.log(zs);
    console.log(zs.classic);
    zs.show();
    var ls = new Person("李四", "女", "28");
    ls.play();

    console.log(zs.classic === ls.classic);
    console.log(zs.play === ls.play); //true 说明play()是共用了一段内存空间
  </script>
</html>
